package com.lkd.handler;

import com.lkd.business.MsgHandler;
import com.lkd.common.VMSystem;
import com.lkd.config.TopicConfig;
import com.lkd.contract.TaskCompleteContract;
import com.lkd.emq.Topic;
import com.lkd.service.VendingMachineService;
import com.lkd.utils.JsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 工单完成处理
 *
 * @author Administrator
 */
@Component
@Topic(TopicConfig.VMS_COMPLETED_TOPIC)
public class TaskCompletedMsgHandler implements MsgHandler {
    @Autowired
    private VendingMachineService vendingMachineService;

    @Override
    public void process(String jsonMsg) throws IOException {
        TaskCompleteContract taskCompleteContract = JsonUtil.getByJson(jsonMsg, TaskCompleteContract.class);
        //将投放工单对应的售货机改为运营状态
        if (taskCompleteContract.getTaskType() == VMSystem.TASK_TYPE_DEPLOY) {
            vendingMachineService.updateStatus(taskCompleteContract.getInnerCode(), VMSystem.VM_STATUS_RUNNING);
        }
        //将撤机工单对应的售货机改为撤机状态
        if (taskCompleteContract.getTaskType() == VMSystem.TASK_TYPE_REVOKE) {
            vendingMachineService.updateStatus(taskCompleteContract.getInnerCode(), VMSystem.VM_STATUS_REVOKE);
        }
    }
}
